package com.lanchetech.admin.controller;

import com.lanchetech.admin.aop.OperatorLog;
import com.lanchetech.admin.service.VipService;
import com.lanchetech.bean.request.BonusCountReq;
import com.lanchetech.bean.request.IdentityReq;
import com.lanchetech.bean.request.PageReq;
import com.lanchetech.bean.request.VipReq;
import com.lanchetech.bean.response.BasePageResp;
import com.lanchetech.bean.response.BaseResp;
import com.lanchetech.bean.response.ResultData;
import com.lanchetech.bean.vo.*;
import com.lanchetech.entity.BonusCount;
import com.lanchetech.entity.ConsumptionRecord;
import com.lanchetech.entity.Honor;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@Api(value = "会员管理接口", tags = "会员管理接口")
@RequestMapping("/api/vip")
@RestController
public class VipController {

    @Autowired
    VipService vipService;

    @ApiOperation(value = "获取会员分页")
    @PreAuthorize("hasAuthority('vip.index')")
    @PostMapping("/getIdentityPage")
    public ResultData<BasePageResp<IdentityVO>> getIdentityPage(@RequestBody IdentityReq req) {
        return vipService.getIdentityPage(req);
    }

    @OperatorLog(value = "设置会员等级")
    @ApiOperation(value = "设置会员等级")
    @PreAuthorize("hasAuthority('vip.index.edit.auth')")
    @GetMapping("/updateUserLevel")
    public BaseResp updateUserLevel(@RequestParam("userId") Long userId, @RequestParam("level") Integer level ) {
        return vipService.updateUserLevel(userId, level);
    }

    @OperatorLog(value = "添加会员")
    @ApiOperation(value = "添加会员")
    @PreAuthorize("hasAuthority('vip.index.edit.auth')")
    @PostMapping("/createUserLevel")
    public BaseResp createUserLevel(@RequestBody VipReq req) {
        return vipService.createUserLevel(req);
    }

    @OperatorLog(value = "删除会员")
    @ApiOperation(value = "删除会员")
    @PreAuthorize("hasAuthority('vip.index.edit.auth')")
    @GetMapping("/deleteIdentity")
    public BaseResp deleteIdentity(@RequestParam("id") Long id) {
        return vipService.deleteIdentity(id);
    }

    @OperatorLog("修改会员消费累计金额")
    @ApiOperation("修改会员消费累计金额")
    @PreAuthorize("hasAuthority('vip.consumption-amount.edit.auth')")
    @PostMapping("/createConsumptionRecord")
    public BaseResp createConsumptionRecord(@RequestBody ConsumptionRecord req) {
        return vipService.createConsumptionRecord(req);
    }

    @OperatorLog(value = "禁止或取消禁止会员分销")
    @ApiOperation(value = "禁止或取消禁止会员分销", notes = "status 1 正常 2 禁止分销")
    @PreAuthorize("hasAuthority('vip.index.edit.auth')")
    @GetMapping("/banUserForCommission")
    public BaseResp banUserForCommission(@RequestParam("userId") Long userId, @RequestParam("status") Integer status) {
        return vipService.banUserForCommission(userId, status);
    }

    @ApiOperation(value = "获取累计消费金额分页", notes = "筛选条件 userId, startTime, endTime")
    @PreAuthorize("hasAuthority('vip.consumption-amount')")
    @PostMapping("/getConsumptionAmountPage")
    public ResultData<BasePageResp<ConsumptionAmountVO>> getConsumptionAmountPage(@RequestBody PageReq req) {
        return vipService.getConsumptionAmountPage(req);
    }

    @ApiOperation(value = "获取消费金额变动分页", notes = "筛选条件 userId, startTime, endTime")
    @PreAuthorize("hasAuthority('vip.consumption-record')")
    @PostMapping("/getConsumptionRecordPage")
    public ResultData<BasePageResp<ConsumptionRecordVO>> getConsumptionRecordPage(@RequestBody PageReq req) {
        return vipService.getConsumptionRecordPage(req);
    }

    @OperatorLog("编辑荣誉")
    @ApiOperation("编辑荣誉")
    @PreAuthorize("hasAuthority('vip.honor.edit.auth')")
    @PostMapping("/editHonor")
    public BaseResp editHonor(@RequestBody Honor req) {
        return vipService.editHonor(req);
    }

    @ApiOperation("获取荣誉分页")
    @PreAuthorize("hasAuthority('vip.honor')")
    @PostMapping("/getHonorPage")
    public ResultData<BasePageResp<HonorVO>> getHonorPage(@RequestBody PageReq req) {
        return vipService.getHonorPage(req);
    }

    @OperatorLog("删除荣誉")
    @ApiOperation("删除荣誉")
    @PreAuthorize("hasAuthority('vip.honor.edit.auth')")
    @GetMapping("/deleteHonor")
    public BaseResp deleteHonor(@RequestParam("id") Long id) {
        return vipService.deleteHonor(id);
    }

    @ApiOperation("获取排单补贴计数列表")
    @PreAuthorize("hasAuthority('vip.bonus-count')")
    @GetMapping("/getBonusCountList")
    public ResultData<List<BonusCount>> getBonusCountList() {
        return vipService.getBonusCountList();
    }

    @ApiOperation("获取排单补贴计数列表分页")
    @PostMapping("/getBonusCountPage")
    public ResultData<BasePageResp<BonusCountVO>> getBonusCountPage(@RequestBody BonusCountReq req) {
        return vipService.getBonusCountPage(req);
    }

    @ApiOperation("获取用户嗨币流水分页")
    @PreAuthorize("hasAuthority('vip.card-flow')")
    @PostMapping("/getCardFlowPage")
    public ResultData<BasePageResp<CardFlowVO>> getCardFlowPage(@RequestBody PageReq req) {
        return vipService.getCardFlowPage(req);
    }

    @ApiOperation("统计时间区间内总的销售金额、退款金额、订单数")
    @PreAuthorize("hasAuthority('vip.index.commission.auth')")
    @PostMapping("/countOrder")
    public ResultData<CountOrderVO> countOrder(@RequestBody PageReq req) {
        return vipService.countOrder(req);
    }

    @ApiOperation("获取补贴奖励排单分页")
    @PreAuthorize("hasAuthority('vip.reward-queue')")
    @PostMapping("/getRewardQueuePage")
    public ResultData<BasePageResp<RewardQueueVO>> getRewardQueuePage(@RequestBody PageReq req) {
        return vipService.getRewardQueuePage(req);
    }

    @OperatorLog("更改补贴奖励发放状态")
    @ApiOperation("更改补贴奖励发放状态")
    @PreAuthorize("hasAuthority('vip.reward-queue.edit.auth')")
    @GetMapping("/issueRewardQueue")
    public BaseResp issueRewardQueue(@RequestParam("id") Long id,  @RequestParam("amount") BigDecimal amount) {
        return vipService.issueRewardQueue(id, amount);
    }



}
